( function() {

		var icon_url = '../wp-content/plugins/woocommerce-post-purchase-followup/followup.png';

		tinymce.create(
			"tinymce.plugins.FollowupTags",
			{
				init: function(d,e) {},
				createControl:function(d,e)
				{

					if ( d == "followup" ) {

						d = e.createMenuButton( "followup", {
							title: "Insert Follow-up Tags",
							image: icon_url,
							icons: false
							});

						var a = this; 

						d.onRenderMenu.add( function( c,b ) {

							a.addImmediate(b,"Customer First Name", '{first_name}');
							a.addImmediate(b,"Customer Last Name", '{last_name}');
							a.addImmediate(b,"Customer Email", '{customer_email}');

							b.addSeparator();
							
							a.addImmediate(b,"Abandoned Cart Contents", '{cart_contents}');

							b.addSeparator();
														
							a.addImmediate(b,"Coupon Codes", '{coupon_code}');
														
							b.addSeparator();

							a.addImmediate(b,"Site Name", '{site_name}');
							a.addImmediate(b,"Site URL", '{site_url}');

						});

						return d;

					}

					return null
				},
		
				addImmediate:function(d,e,a) { 
				    d.add( 
					{ title:e,onclick:function() { tinyMCE.activeEditor.execCommand( "mceInsertContent", false, a ) } }
				    )
				}
	
			}
		);

		tinymce.PluginManager.add( "followup", tinymce.plugins.FollowupTags );
})();